package com.trg.designmodel.factory.methodfactory.order;

import com.trg.designmodel.factory.methodfactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @ClassName: OrderPizza
 * @Description: pizza订购
 * @Author: tangrg
 * @Date: 2021/7/1 10:27
 * @Version: 1.0
 * @Return:
 **/
public abstract class OrderPizza {

    abstract Pizza createPizza(String orderType);

    /**
     * 3、静态工厂的方式
     *
     * @return
     */

    public OrderPizza() {
        String pizzaType = null;
        Pizza pizza2 = null;
        do {
            pizzaType = getType2();
            pizza2 = createPizza(pizzaType);
            if (pizza2 != null) { //订购成功
                pizza2.prepare();
                pizza2.bake();
                pizza2.cut();
                pizza2.box();
            } else {
                System.out.println(" 订购披萨失败 ");
                break;
            }


        } while (true);

    }


    public static String getType2() {
        try {
            BufferedReader inpput = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("请输入披萨种类：");
            String s = inpput.readLine();
            return s;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }


}
